package cn.e4j.modular.crm.controller.bb;

import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.core.reqres.response.SuccessResponseData;
import cn.e4j.core.util.ToolUtil;
import cn.e4j.modular.api.service.BbJcryfhService;
import cn.e4j.modular.api.util.ControllerSupport;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Calendar;
import java.util.List;

/**
 * 检测人员负荷
 */
@Controller
@RequestMapping("/bb/jcryfh")
public class BbJcryfhController extends ControllerSupport {

    @Autowired
    BbJcryfhService bbJcryfhService;


    /**
     * 跳转页面
     */
    @RequiresPermissions("bb:jcryfh:init")
    @RequestMapping(value = {"", "init"})
    public String index() {
        return "/pc/crm/bb/jcryfh.html";
    }



    @RequiresPermissions("bb:jcryfh:init")
    @ResponseBody
    @RequestMapping(value = "getListData")
    public ResponseData getListData(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        if(ToolUtil.isNotEmpty(inDto.getString("AREA"))){
            inDto.put("AREA_LIST", inDto.getString("AREA").split(","));
        }
        Calendar calendar = Calendar.getInstance();
        inDto.put("YEAR", calendar.get(Calendar.YEAR));
        if("MONTH".equals(inDto.getString("TIME"))){
            inDto.put("MONTH_START", calendar.get(Calendar.MONTH) + 1);
            inDto.put("MONTH_END", calendar.get(Calendar.MONTH) + 1);
        }else if("LAST_MONTH".equals(inDto.getString("TIME"))){
            inDto.put("MONTH_START", calendar.get(Calendar.MONTH));
            inDto.put("MONTH_END", calendar.get(Calendar.MONTH));
        }else if("QUARTER".equals(inDto.getString("TIME"))){
            inDto.put("MONTH_START", calendar.get(Calendar.MONTH) / 3 * 3);
            inDto.put("MONTH_END", calendar.get(Calendar.MONTH) / 3 * 3 + 3);
        }else if("YEAR".equals(inDto.getString("TIME"))){
            inDto.put("MONTH_START", 1);
            inDto.put("MONTH_END", 12);
        }
        return new SuccessResponseData(bbJcryfhService.getListData(inDto));
    }

}
